﻿Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath({
	'Ext.ux':'/resources/ux',
	'MyDesktop': '/js'
});
Ext.require('MyDesktop.App');
Ext.onReady(function() {
	Ext.BLANK_IMAGE_URL = '/resources/themes/images/default/s.gif';
	Ext.Ajax.request({
		url: '/interface.php',
		params: {
			type:'has_login'
		},
		success: function(response){
			if (response.responseText == 'success'){
				if (Ext.fly('starting')){
					Ext.fly('starting').remove();
				}
				if (Ext.fly('loading')){
					Ext.fly('loading').remove();
				}
				if (!Ext.ModelManager.isRegistered('userinfo_model')){
					Ext.define('userinfo_model', {
						extend: 'Ext.data.Model',
						idProperty:'id',
						fields: [
							 {name: 'id', type: 'int'},
							 {name: 'name', type: 'string'},
							 {name: 'privileges', type: 'string'},
							 {name: 'create_time'},
							 {name: 'login_time'}	 
						]
					});
				}
				Ext.create('Ext.data.Store',{
					storeId:'userinfo_store',
					model: 'userinfo_model',
					buffered: true,
					proxy: {
						type: 'memory',
						reader: {
							type: 'json'
						}
					}
				});
				Ext.Ajax.request({
                    url: '/interface.php',
                    params: {
                        type:'userinfo'
                    },
                    success: function(response){
                        var tmp = new Array();
                        var tmp2 = Ext.decode(response.responseText);
                        tmp.push({'id':tmp2.userinfo.id,'name':tmp2.userinfo.name,'privileges':tmp2.userinfo.privileges,'create_time':tmp2.userinfo.create_time,'login_time':tmp2.userinfo.login_time});
                        Ext.getStore('userinfo_store').add(tmp);
                        var myDesktopApp = new MyDesktop.App();;
                        return myDesktopApp;
                    }
				});
			}else{
				location.href="index.html";
			}
		}
	});
});
